package com.longge;

import java.util.Stack;

/**
 * @program: my-code
 * @description:
 * @author: longge
 * @create: 2021-04-13 02:43
 */
public class IsPalindrome {

    public boolean isPalindrome(ListNode head) {
        ListNode fast = head, slow = head;
        Stack<Integer> arr = new Stack<>();
        while (fast != null && fast.next != null) {
            arr.push(slow.val);
            slow = slow.next;
            fast = fast.next.next;

        }
        if (arr.empty()) return true;
        if (fast != null) slow = slow.next;
        while (slow != null && slow.val == arr.pop()) {
            slow = slow.next;
        }
        return slow == null;
    }
}
